<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>图片轮播</title>
    <style>
        #bigdiv {
            width: 700px;
            height: 500px;
            margin: 0 auto;
            background-color: aqua;
        }
    </style>
</head>

<body>
    <!-- setInterval:实现图片轮播 -->
    <div id="bigdiv">
        <img src="./img/1.jpg" style="width: 700px ;height: 500px;">
    </div>
    <script>
        var img = document.getElementsByTagName('img')[0];
        var count = 0;
        const aaa = ['1.jpg', '2.jpg', '3.jpg', '4.jpg']
        function fn() {
            if (count < 3) {
                count++;
            } else {
                count = 0;
            }

            img.src = './img/' + aaa[count];
            return setTimeout(fn, 3000);
        }
        setTimeout(fn, 3000);
    </script>
</body>

</html>